package test01.demo04.controller;

import test01.demo02.userOperation.tools.Const;
import test01.demo04.pojo.Person;
import test01.demo04.service.PersonService;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

public class PersonController {

    PersonService ps = new PersonService();

    public void testInsertPerson(){

        Person person1 = new Person(
                UUID.randomUUID().toString().toUpperCase(),
                "郭德纲",
                "小本",
                LocalDate.of(1970,6,4).format(DateTimeFormatter.ofPattern(Const.DATEFORMATTER)),
                1000000
        );
        Person person2 = new Person(
                UUID.randomUUID().toString().toUpperCase(),
                "于谦",
                "幼本",
                LocalDate.of(1965,9,28).format(DateTimeFormatter.ofPattern(Const.DATEFORMATTER)),
                100000
        );
        Person person3 = new Person(
                UUID.randomUUID().toString().toUpperCase(),
                "岳云鹏",
                "胎本",
                LocalDate.of(1985,2,11).format(DateTimeFormatter.ofPattern(Const.DATEFORMATTER)),
                80000
        );

        boolean result = ps.insert(person1,person2,person3);
        if (result){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }

    }

    public void testDeletePerson(){

        String[] str = {"25149306-B511-4741-A84A-B20A67127F4D"};

        boolean result = ps.delete(str);
        if (result){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }

    }

    public void testUpdatePerson(){

        Person person = new Person("A1C6A66B-065D-4C0F-B281-465DC6D67F0B",
                "哈哈哈",
                "幼本",
                LocalDate.of(1965,9,28).format(DateTimeFormatter.ofPattern(Const.DATEFORMATTER)),
                100000);
        int result = ps.update(person);
        if (result==1){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    public void testGetPersonById(){
        System.out.println(ps.getPersonById("D6E78867-38C1-4704-83A4-222F618C6964"));
    }

    public void testGetAll(){
        System.out.println(ps.getAll());
    }
    public void testGetPersonForPage(){
        System.out.println(ps.getPersonForPage(2,2));
    }

    public static void main(String[] args) {
        PersonController pc = new PersonController();
        //pc.testInsertPerson();
        //pc.testUpdatePerson();
        //pc.testGetPersonById();
        //pc.testDeletePerson();
        //pc.testGetAll();
        pc.testGetPersonForPage();
    }
}
